//新增
function add(){
    var url ="/role/toAddR.shtml" ;
    parent.layer.open({
        type : 2,
        shadeClose : false,
        title : [ '新增角色', 'border:none; background:#4E96EC; color:#fff;' ],
        shade : [ 0.8, '#000' ],
        border : [ 0 ],
        area : [ '750px', '490px' ],
        content : url,
        btns : 2,
        btn : [ "提交", "取消" ],
        yes : function(index) {
            //var $form = top.$("#xubox_layer" + index + " form");
            var $formFile  = parent.layer.getChildFrame('#jvForm', index);
            $formFile.ajaxSubmit({


                dataType : "json",
                beforeSend : function(XHR) {
                    //return $form.form("validate");
                },
                success : function(data) {
                    if (data) {
                        parent.layer.close(index);
                        location.reload();
                        parent.layer.msg("角色添加成功",{shade: false,icon: 1,shift:5});
                    }else{
                        parent.layer.msg("角色添加失败",{shade: false,icon: 5,shift:5});
                    }

                },
                error : function(e, s1, s2) {
                    parent.layer.msg("角色添加失败",{shade: false,icon:5,shift:5});
                },
            });
            return false;
        }
    });
}

//修改
function editUser(user_id){
    var param=user_id;
    if (user_id == null||user_id=="") {
        parent.layer.msg("请先选择要编辑的角色",{shade: false,icon: 5,shift:5});
        return;
    }
    var url ="/role/toEditR.shtml?user_id="+param ;
    parent.layer.open({
        type : 2,
        shadeClose : false,
        title : [ '编辑角色', 'border:none; background:#4E96EC; color:#fff;' ],
        shade : [ 0.8, '#000' ],
        border : [ 0 ],
        area : [ '750px', '490px' ],
        content : url,
        btns : 2,
        btn : [ "提交", "取消" ],
        yes : function(index) {
            //var $form = top.$("#xubox_layer" + index + " form");
            var $form  = parent.layer.getChildFrame('#jvForm', index);
            $form.ajaxSubmit({
                dataType : "json",
                beforeSend : function(XHR) {
                    //return $form.form("validate");
                },
                success : function(data) {
                    if (data) {
                        parent.layer.close(index);
                        window.location.reload();
                        parent.layer.msg("修改角色成功",{shade: false,icon: 1,shift:5});
                    }else{
                        parent.layer.msg("修改角色失败",{shade: false,icon: 5,shift:5});
                    }

                },
                error : function(e, s1, s2) {
                    parent.layer.msg("修改角色失败",{shade: false,icon:5,shift:5});
                },
            });
            return false;
        }
    });
}

//删除
function delUser(ROLE_ID,msg){
    var typeData = ROLE_ID;
    if (typeData == null || typeData == undefined || typeData == "") {
        parent.layer.msg("请先选择要删除的角色",{shade: false,icon: 5,shift:5});
        return;
    }
    var url = "/role/deleteR.shtml";
    var load = parent.layer.msg("正在删除，请稍等...", { icon : 16 });
    $.ajax({
        url:url,
        dataType:'json',
        data:{"ROLE_ID":typeData},
        success:function(data){
            parent.layer.close(load);
            parent.layer.msg("删除角色成功",{shade: false,icon: 1,shift:5});
            window.location.reload();
        }
    });
}

//批量操作
function makeAll(msg){
    var str = '';
    for(var i=0;i < document.getElementsByName('ids').length;i++)
    {
        if(document.getElementsByName('ids')[i].checked){
            if(str=='') str += document.getElementsByName('ids')[i].value;
            else str += ',' + document.getElementsByName('ids')[i].value;
        }
    }
    //var typeData = str;
    if (str == null || str == undefined || str == "") {
        parent.layer.msg("请先选择要批量删除的角色",{shade: false,icon: 5,shift:5});
        return;
    }
    var url = "/role/deletesR.shtml";
    var load = parent.layer.msg("正在批量删除，请稍等...", { icon : 16 });
    $.ajax({
        url:url,
        dataType:'json',
        data:{"userIds":str},
        success:function(data){
            parent.layer.close(load);
            parent.layer.msg("批量删除角色成功",{shade: false,icon: 1,shift:5});
            window.location.reload();
        }
    });

}

